#include <map>
#include <cmath>
#include <cstdio>
using namespace std;
map<int,int>mp;
int i,j,k,n,m,x,y,t,p,b;
int main(){
    scanf("%d%d%d",&p,&b,&n);
    if (n==1)return printf("0\n"),0;
    int block=sqrt(p)+1;
    for (i=0;i<block;i++){
        if (!mp[n])mp[n]=i+1;
        n=1ll*b*n%p;
    }
    int nb=1,te=1;
    for (i=1;i<=block;i++)nb=1ll*nb*b%p;
    for (i=1;i<=block;i++){
        te=1ll*te*nb%p;
        if (mp[te])return printf("%d\n",i*block-(mp[te]-1)),0;
    }
    printf("no solution\n");
    return 0;
}
//b^l % p=n